package com.alibaba.dingtalk.openapi.demo.message;

import com.alibaba.dingtalk.openapi.demo.Env;
import com.alibaba.dingtalk.openapi.demo.OApiException;
import com.alibaba.dingtalk.openapi.demo.auth.AuthHelper;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.CorpMessageCorpconversationAsyncsendRequest;
import com.dingtalk.api.request.CorpMessageCorpconversationAsyncsendbycodeRequest;
import com.dingtalk.api.response.CorpMessageCorpconversationAsyncsendResponse;
import com.dingtalk.api.response.CorpMessageCorpconversationAsyncsendbycodeResponse;
import com.taobao.api.ApiException;

/**
 * Created by wjy on 2017/9/18.
 */
public class MessageTest {
    public static void main(String[] args) throws OApiException, ApiException {
//        DingTalkClient client = new DefaultDingTalkClient("https://eco.taobao.com/router/rest");
//        CorpMessageCorpconversationAsyncsendRequest req = new CorpMessageCorpconversationAsyncsendRequest();
//        req.setMsgtype("text");
//        req.setAgentId(Long.parseLong(Env.AGENT_ID));
//        req.setUseridList("015458481229202584");
//        req.setDeptIdList("49562011");
//        req.setToAllUser(false);
//        String messageContent = "{\"msgtype\": \"text\", \"text\": {\"content\": \"张三的请假申请\"}}";
//        //req.setMsgcontentString("{\"message_url\": \"http://dingtalk.com\",\"head\": {\"bgcolor\": \"FFBBBBBB\",\"text\": \"头部标题\"},\"body\": {\"title\": \"正文标题\",\"form\": [{\"key\": \"姓名:\",\"value\": \"张三\"},{\"key\": \"爱好:\",\"value\": \"打球、听音乐\"}],\"rich\": {\"num\": \"15.6\",\"unit\": \"元\"},\"content\": \"大段文本大段文本大段文本大段文本大段文本大段文本大段文本大段文本大段文本大段文本大段文本大段文本\",\"image\": \"@lADOADmaWMzazQKA\",\"file_count\": \"3\",\"author\": \"李四 \"}}");
//        req.setMsgcontentString(messageContent);
//        req.set
//        String accessToken = AuthHelper.getSsoToken();
//        CorpMessageCorpconversationAsyncsendResponse rsp = client.execute(req, accessToken);
//        System.out.println(rsp.getBody());



        DingTalkClient client = new DefaultDingTalkClient("https://eco.taobao.com/router/rest");
        CorpMessageCorpconversationAsyncsendbycodeRequest req = new CorpMessageCorpconversationAsyncsendbycodeRequest();
        req.setMsgtype("text");
        req.setAgentId(Long.parseLong(Env.AGENT_ID));
        req.setUserIdList("015458481229202584");
        req.setDeptIdList("49562011");
        req.setToAllUser(false);//
        String messageContent = "{\"msgtype\": \"text\", \"text\": {\"content\": \"张三的请假申请\"}}";
        req.setMsgcontentString(messageContent);
        req.setCode("7dsf78d78sf87sd");
        String accessToken = AuthHelper.getSsoToken();
        CorpMessageCorpconversationAsyncsendbycodeResponse rsp = client.execute(req, accessToken);
        System.out.println(rsp.getBody());
    }
}
